<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page isELIgnored="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <%@include file="/styles/common/cssStyle.jsp" %>
    <title>商品列表</title>
  </head>
  
  <body>
  	<!-- 通知、导航栏 -->
	<nav class="breadcrumb">
		<i class="Hui-iconfont">&#xe67f;</i> 首页 
		<span class="c-gray en">&gt;</span> 商品管理 
		<span class="c-gray en">&gt;</span> 商品列表
	</nav>
        <!-- 内容 -->
        <div class="page-container">
        	<div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
					<a class="btn btn-primary radius" data-title="添加商品" href="javascript:;" onclick="add('商品新增','<%=basePath%>admin/goods/toGoodsAdd','800','500')">
					<i class="Hui-iconfont">&#xe600;</i> 添加商品</a>
				</span>
  			</div>
	  		<div class="mt-20">
		    	<table class="table table-border table-bordered table-bg table-hover table-sort">
		    	<thead>
		    		<tr class="text-c">
						<th>序号</th>
						<th>商品名称</th>
						<th>商品价格</th>
						<th>图片展示</th>
						<th>商品简介</th>
						<th>出厂日期</th>
						<th>商品库存</th>
						<th>是否展示</th>
						<th>商品类别</th>
						<th>页面位置</th>
						<th>展示顺序</th>
						<th width="10%">操作</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${goodsList }" var="goods" varStatus="nb" >
					<c:if test="${goods.goodsNum > 0 }">
						<tr class="text-c">
							<td>${nb.count }</td>
							<td>${goods.goodsName }</td>
							<td>${goods.goodsPrice }</td>
							<td>
								<img alt="暂无图片" width="210" src="<%=basePath %>${goods.goodsImg }">
							</td>
							<td>${goods.goodsContent.substring(0,11) }<br/><a href="">>>更多</a></td>
							<td>${goods.goodsDate }</td>
							<td>${goods.goodsNum }</td>
							<td>${goods.goodsRec==null?'未设置':(goods.goodsRec==1?'是':'否') }</td>
							<td>
								<c:forEach items="${goodsTypesList }" var="goodsTypes">
									<c:if test="${goodsTypes.pId == 0 }">
										<c:if test="${goods.goodsTypeId == goodsTypes.goodsTypeId }">
											${goodsTypes.goodsTypeName }
										</c:if>
									</c:if>
									<c:if test="${goodsTypes.pId != 0 }">
										<c:if test="${goods.goodsTypeId == goodsTypes.goodsTypeId }">
											${goodsTypes.pname }-->${goodsTypes.goodsTypeName }
										</c:if>
									</c:if>
								</c:forEach>
							</td>
							<td>
								${goods.goodsRec==1?(goods.pageType==1?'热销产品':'商家推荐'):'不展示'}
							</td>
							<td>${goods.goodsOrder }</td>
							<td width="20%">
								<a title="修改" href="javascript:;" onclick="edit('商品修改','<%=basePath%>admin/goods/toGoodsUpdate','${goods.goodsId }','800','500')" class="ml-5" style="text-decoration:none">
									<i class="Hui-iconfont">&#xe6df;</i>
								</a>
								&nbsp;
								<a title="删除" href="javascript:;" onclick="del(this,'${goods.goodsId}','${goods.goodsName }')" class="ml-5" style="text-decoration:none">
									<i class="Hui-iconfont">&#xe6e2;</i>
								</a>
							</td>
						</tr>
					</c:if>
					</c:forEach>
				</tbody>	
		    	</table>
		    </div>
		</div>
	<%@include file="/styles/common/jsStyle.jsp" %>
	<script type="text/javascript">
	// 分页
	$('.table-sort').dataTable({
		"aaSorting": [[ 0, "asc" ]],//默认第几个排序
		"bStateSave": false,//状态保存
		"aoColumnDefs": [
		  {"orderable":false,"aTargets":[0]}// 写出：不参与   排序的列
		]
	});
	
	//删除
	function del(obj,goodsId,goodsName){
		layer.confirm("确定要删除<span style='color:red;'>..." + goodsName + "...</span>商品吗?",function(index){
			var url = "<%=basePath%>admin/goods/deleteGoods";
			var params = {};
			params.goodsId = goodsId;
			$.post(url,params,function(obj){
				//alert(result);
				if(obj){
					$(obj).parents("tr").remove();
					layer.msg('已删除!',{icon:1,time:1000});
					location.reload();
				}else{
					layer.msg('删除失败!',{icon:1,time:1000});
				}
			});
		});
	}
	
	// 添加
	function add(title,url,w,h){
		layer_show(title,url,w,h);
	}
	
	// 修改
	function edit(title,url,goodsId,w,h){
		url = url + "?goodsId=" + goodsId;
		layer_show(title,url,w,h);
	}
	
	</script>	
  </body>
</html>
